﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;

namespace DeskRedis.Util
{
    public static class RedisValueUtil
    {
        /// <summary>
        /// 创建文本框。
        /// </summary>
        /// <returns></returns>
        public static TextBox CreateTextBox()
        {
            TextBox tb = new TextBox();
            tb.TextWrapping = TextWrapping.Wrap;
            tb.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
            return tb;
        }

        /// <summary>
        /// 创建List类型的UCRedisValue。
        /// </summary>
        /// <returns></returns>
        public static DataGrid CreateDataGrid4List()
        {
            DataGrid grid = CreateDataGrid();
            DataGridTextColumn columnValue = new DataGridTextColumn()
            {
                Header = "值",
                Binding = new Binding("."),
                Width = new DataGridLength(1, DataGridLengthUnitType.Star)
            };
            grid.Columns.Add(columnValue);
            return grid;
        }

        /// <summary>
        /// 创建Set类型的UCRedisValue。
        /// </summary>
        /// <returns></returns>
        public static DataGrid CreateDataGrid4Set()
        {
            DataGrid grid = CreateDataGrid();
            DataGridTextColumn columnValue = new DataGridTextColumn()
            {
                Header = "值",
                Binding = new Binding("."),
                Width = new DataGridLength(1, DataGridLengthUnitType.Star)
            };
            grid.Columns.Add(columnValue);
            return grid;
        }

        /// <summary>
        /// 创建Zset类型的UCRedisValue。
        /// </summary>
        /// <returns></returns>
        public static DataGrid CreateDataGrid4Zset()
        {
            DataGrid grid = CreateDataGrid();
            DataGridTextColumn columnValue = new DataGridTextColumn()
            {
                Header = "值",
                Binding = new Binding("Key"),
                Width = new DataGridLength(1, DataGridLengthUnitType.Star)
            };
            DataGridTextColumn columnScore = new DataGridTextColumn()
            {
                Header = "排序号",
                Binding = new Binding("Value"),
                Width = new DataGridLength(100)
            };
            grid.Columns.Add(columnValue);
            grid.Columns.Add(columnScore);

            return grid;
        }

        /// <summary>
        /// 创建hash类型的UCRedisValue。
        /// </summary>
        /// <returns></returns>
        public static DataGrid CreateDataGrid4Hash()
        {
            DataGrid grid = CreateDataGrid();
            DataGridTextColumn columnKey = new DataGridTextColumn()
            {
                Header = "键",
                Binding = new Binding("Key"),
                MinWidth = 130,
                Width = 130
            };
            DataGridTextColumn columnValue = new DataGridTextColumn()
            {
                Header = "值",
                Binding = new Binding("Value"),
                Width = new DataGridLength(1, DataGridLengthUnitType.Star)
            };
            grid.Columns.Add(columnKey);
            grid.Columns.Add(columnValue);

            return grid;
        }


        #region 私有方法
        /// <summary>
        /// 创建数据表格。
        /// </summary>
        /// <returns></returns>
        private static DataGrid CreateDataGrid()
        {
            DataGrid grid = new DataGrid();
            grid.CanUserAddRows = false;
            grid.CanUserDeleteRows = false;
            grid.CanUserReorderColumns = false;
            grid.CanUserResizeColumns = false;
            grid.CanUserResizeRows = false;
            grid.CanUserSortColumns = false;
            grid.AlternationCount = 3;
            grid.AutoGenerateColumns = false;
            grid.IsReadOnly = true;

            return grid;
        }
        #endregion
    }
}
